package com.gitee.cirnochat.user.controller;

import com.gitee.cirnochat.common.annotation.AuthCheck;
import com.gitee.cirnochat.common.model.vo.resp.Result;
import com.gitee.cirnochat.common.utils.RequestUtils;
import com.gitee.cirnochat.user.model.vo.req.user.UserPrivacySettingUpdateReq;
import com.gitee.cirnochat.user.model.vo.resp.UserPrivacySettingVo;
import com.gitee.cirnochat.user.service.UserPrivacySettingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户隐私设置接口", description = "用户隐私设置相关API")
@RestController
@RequestMapping("/user/privacy")
@RequiredArgsConstructor
public class UserPrivacySettingController {
    private final UserPrivacySettingService userPrivacySettingService;


    @Operation(summary = "获取隐私设置", description = "获取当前用户的隐私设置")
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = UserPrivacySettingVo.class)
            )
    )
    @AuthCheck
    @Parameter(name = "Authorization", description = "认证信息", required = true, in = ParameterIn.HEADER)
    @GetMapping
    public Result<UserPrivacySettingVo> getPrivacySetting(HttpServletRequest request) {
        Long userId = RequestUtils.getUserId(request);
        return Result.success(userPrivacySettingService.getPrivacySettingByUserId(userId));
    }

    @Operation(summary = "更新隐私设置", description = "更新当前用户的隐私设置")
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = Result.class)
            )
    )
    @AuthCheck
    @Parameter(name = "Authorization", description = "认证信息", required = true, in = ParameterIn.HEADER)
    @PutMapping
    public Result<Void> updatePrivacySetting(@RequestBody UserPrivacySettingUpdateReq req,
                                             HttpServletRequest request) {
        Long userId = RequestUtils.getUserId(request);
        userPrivacySettingService.updatePrivacySetting(req, userId);
        return Result.success();
    }

    @Operation(summary = "重置隐私设置", description = "将用户隐私设置恢复为默认值")
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = Result.class)
            )
    )
    @AuthCheck
    @Parameter(name = "Authorization", description = "认证信息", required = true, in = ParameterIn.HEADER)
    @DeleteMapping("/reset")
    public Result<Void> resetPrivacySetting(HttpServletRequest request) {
        Long userId = RequestUtils.getUserId(request);
        userPrivacySettingService.resetPrivacySetting(userId);
        return Result.success();
    }


}